class Solution {
    public String multiply(String num1, String num2) {
        int len1 = num1.length(), len2 = num2.length();
        if (len1 == 1 && num1.charAt(0) - '0' == 0 || len2 == 1 && num2.charAt(0) - '0' == 0) {
            return "0";
        }
        int[] sums = new int[len1 + len2];

        int[] nums1 = new int[len1];
        for (int i = 0; i < len1; i++) {
            nums1[i] = num1.charAt(i) - '0';
        }

        for (int i = 0; i < len2; i++) {
            int multiply1 = num2.charAt(len2 - i - 1) - '0';
            for (int j = 0; j < len1; j++) {
                sums[i + j] += (multiply1 * nums1[len1 - j - 1]);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sums.length; i++) {
            if (sums[i] >= 10) {
                sums[i + 1] += sums[i] / 10;
                sums[i] = sums[i] % 10;
            }
            if (i == sums.length - 1 && sums[i] == 0) {
                continue;
            }
            sb.append(sums[i]);
        }

        return sb.reverse().toString();
    }
}